package com.gupaoedu.concurrent.thread;

import java.util.concurrent.TimeUnit;

/**
 * 2019/5/12
 * created by chenpp
 */
public class InterruptDemo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            try {

                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
                Thread.currentThread().interrupt();
                System.out.println("收到了外部的interrupt指令"+Thread.currentThread().isInterrupted());
            }
            int i=0;
            while (i<100){
                i++;
            }
            System.out.println(i);
        });
        thread.start();

        TimeUnit.SECONDS.sleep(1);
        thread.interrupt(); //把isInterrupted设置成true
        System.out.println(thread.isInterrupted());

    }
}
